<?php

class controller_index extends base_module
{
    protected $Index;

    public function __construct()
    {
        $this->Index = RpcClient::instance("Index");
        parent::__construct();
    }

    public function index()
    {
        echo json_encode(array(
           'state' => 404,
           'msgid' => 404,
        ));
    }
    # 热更新升级
    public function wgt()
    {
        $data = $this->Index->appWgtHotUpdate($this->paras);
        if($data['state']==200) {
            $result = $data['data'];
            echo json_encode($result);
        }else{
            echo json_encode($this->result);
        }
    }

    # region 生成二维码
    public function qcode()
    {
        if(!$this->paras){
            return $this->result;
        }

        $data = $this->Index->markQrcode($this->paras);

        if($data['state']==200) {
            $result = $data['data'];
            echo json_encode($result);
        }else{
            echo json_encode($this->result);
        }
    }
    # endregion

    # region 排行榜数据
    public function ranking()
    {
        $type = array_key_exists('t', $this->paras) ? strtoupper($this->paras['t']) : 'D'; // d=> day m=>month y=>year
        switch ($type)
        {
            case 'Y':
                $data = $this->Index->rankingForYear($this->paras);
                break;
            case 'W':
                $data = $this->Index->rankingForWeek($this->paras);
                break;
            case 'M':
                $data = $this->Index->rankingForMonth($this->paras);
                break;
            default:
                $data = $this->Index->rankingForDay($this->paras);
                break;

        }
        if($data['state']==200) {
            $result = $data['data'];
            echo json_encode($result);
        }else{
            echo json_encode($this->result);
        }

    }
    # endregion

    # region 拉取单个的系统参数
    public function systemparams()
    {
        $data = $this->Index->systemParams($this->paras);
        if($data['state']==200) {
            $result = $data['data'];
            echo json_encode($result);
        }else{
            echo json_encode($this->result);
        }
    }
    # endregion
}